import org.apache.shiro.codec.Base64;
import org.apache.shiro.crypto.hash.Md5Hash;

/**
 * 密码加密工具类
 * Created by wuhainan on 2017/2/22.
 */
public class CryptographyUtil {
    /**
     * Base64加密
     * @param encode
     * @return
     */
    public static String encodeBase64(String encode){

        return Base64.encodeToString(encode.getBytes());
    }

    /**
     * Base64解密
     * @param decode
     * @return
     */
    public static String decodeBase64(String decode){
        return Base64.decodeToString(decode);
    }

    /**
     * Md5加密
     * @param password
     * @param salt
     * @return
     */
    public static String md5(String password,String salt){
        return new Md5Hash(password,salt).toString();
    }
    public static void main(String[] args) {
        String userName="json";
        String password="456";
        System.out.println("Base64加密"+CryptographyUtil.encodeBase64(password));
        System.out.println("Base64解密"+CryptographyUtil.decodeBase64(
                CryptographyUtil.encodeBase64(password)));
        System.out.println("Md5加密"+CryptographyUtil.md5(password,userName));
    }
}
